package com.sanalkitaplik.admin;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;

import javax.faces.event.ActionEvent;
import javax.faces.model.SelectItem;

import com.sanalkitaplik.hibernateutil.AdminsUtil;

public class AdminEditAdminManager {
	
	private String editedAdminUserName;
	private String editedPassword;
	private String editedPasswordCheck;
	private String editedEmail;
	private String editedFirstName;
	private String editedLastName;
	
	private boolean isEditing;
	private boolean adminFound;
	private String selectedAdmin;
	private List<SelectItem> admins;
	
	public AdminEditAdminManager() {
		setEditedAdminUserName("");
		setEditedPassword("");
		setEditedPasswordCheck("");
		setEditedEmail("");
		setEditedFirstName("");
		setEditedLastName("");
		
		adminFound = false;
		isEditing = false;
		setSelectedAdmin("");
		this.admins = null;
	}

	public void setSelectedAdmin(String selectedAdmin) {
		this.selectedAdmin = selectedAdmin;
	}

	public String getSelectedAdmin() {
		return selectedAdmin;
	}

	public List<SelectItem> getAdmins() {
		return admins;
	}

	public void setEditedAdminUserName(String editedAdminUserName) {
		this.editedAdminUserName = editedAdminUserName;
	}

	public String getEditedAdminUserName() {
		return editedAdminUserName;
	}

	public void setEditedPassword(String editedPassword) {
		this.editedPassword = editedPassword;
	}

	public String getEditedPassword() {
		return editedPassword;
	}

	public void setEditedPasswordCheck(String editedPasswordCheck) {
		this.editedPasswordCheck = editedPasswordCheck;
	}

	public String getEditedPasswordCheck() {
		return editedPasswordCheck;
	}

	public void setEditedEmail(String editedEmail) {
		this.editedEmail = editedEmail;
	}

	public String getEditedEmail() {
		return editedEmail;
	}

	public void setEditedFirstName(String editedFirstName) {
		this.editedFirstName = editedFirstName;
	}

	public String getEditedFirstName() {
		return editedFirstName;
	}

	public void setEditedLastName(String editedLastName) {
		this.editedLastName = editedLastName;
	}

	public String getEditedLastName() {
		return editedLastName;
	}

	public boolean getIsEditing() {
		return isEditing;
	}

	public boolean getAdminFound() {
		return adminFound;
	}
	
	public void findAdmin(ActionEvent event) {
		try {
			HashMap<String, Object> info = AdminsUtil.getAdminInfo(selectedAdmin);
			if (info.isEmpty()) {
				adminFound = false;
				System.out.println("Bulunamadı");
			} else {
				setEditedAdminUserName((String)info.get("username"));
				setEditedPassword((String)info.get("password"));
				setEditedPasswordCheck((String)info.get("password"));
				setEditedEmail((String)info.get("email"));
				setEditedFirstName((String)info.get("firstname"));
				setEditedLastName((String)info.get("lastname"));
				adminFound = true;
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		isEditing = true;
	}

}
